package com.api.service.impl;

import com.api.common.ErrorCode;
import com.api.exception.BusinessException;
import com.api.model.enums.InterfaceStatusEnum;
import com.apicommon.model.entity.InterfaceInfo;
import com.api.mapper.InterfaceInfoMapper;
import com.api.service.InterfaceInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
* @author HYTZ
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2023-03-20 21:53:47
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo> implements InterfaceInfoService {

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {

    }

    @Override
    public boolean checkInterface(Long id) {

        InterfaceInfo oldInterfaceInfo = this.getById(id);
        if (oldInterfaceInfo == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "接口不存在");
        }

        if (oldInterfaceInfo.getStatus() != InterfaceStatusEnum.ONLINE.getValue()) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "接口关闭");
        }

        return true;
    }
}




